package net.zoneland.greenleaf.timer.service;


import org.apache.log4j.Logger;

import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.UUID;

import net.zoneland.greenleaf.timer.dao.Log_timer_runlogDao;
import net.zoneland.greenleaf.timer.entity.Log_timer_runlog;

import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * LOG_TIMER_RUNLOG[定时代理运行日志]表操作Serfice实现类

 * 类   名：Log_timer_runlogServiceImpl<br/>
 * 表   名：LOG_TIMER_RUNLOGSERVICEIMPL<br/>
 * 注   释：<br/>
 * 作   者：GREENLEAF<br/>
 * 单   位：浙江兰德纵横网络技术有限公司<br/>
 * 日   期：2014-09-03 20:35:13
**/
@Service("log_timer_runlogService")
public class Log_timer_runlogServiceImpl implements Log_timer_runlogServiceI { 

	public static Logger logger = Logger.getLogger(Log_timer_runlogServiceImpl.class);
	
	/**
	 * 自动注入DAO对象
	**/
	@Autowired
	private Log_timer_runlogDao log_timer_runlogDao;

	/**
	 * 新增或者更新数据方法接口
	**/
	@Override
	public boolean addOrUpdate(Log_timer_runlog log_timer_runlog){
		try {
			Log_timer_runlog log_timer_runlog_temp = null;
			if (log_timer_runlog == null) {
				logger.warn(Log_timer_runlog.class.getName() + "对象参数信息为Empty！");
				return false;
			}
			Map map = new HashMap();
			map.put("id", log_timer_runlog.getId());
			List list  = log_timer_runlogDao.getList(map);
			if(list!=null &&list.size()>0){
				//说明 数据已经存在,直接更新数据
				log_timer_runlogDao.edit(log_timer_runlog);
				return true;
			}else{
				//说明 数据目前不存在
				log_timer_runlog.setId( UUID.randomUUID() + "" );
				log_timer_runlogDao.add(log_timer_runlog);
				return true;
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	/**
	 * 新增数据方法实现
	**/
	@Override
	public boolean add(Log_timer_runlog log_timer_runlog){
		try {
			log_timer_runlog.setId( UUID.randomUUID() + "" );
			log_timer_runlogDao.add( log_timer_runlog );
			return true;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	/**
	 * 更新数据方法实现
	**/
	@Override
	public boolean update(Log_timer_runlog log_timer_runlog){
		try {
			log_timer_runlogDao.edit( log_timer_runlog );
			return true;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	/**
	 * 查询数据方法实现
	**/
	@Override
	public Log_timer_runlog get( Map map ) {
		try {
			return log_timer_runlogDao.get( map );
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	/**
	 * 查询数据方法实现（列表）
	**/
	@Override
	public List<Log_timer_runlog> getList(Map map){ 
		List<Log_timer_runlog> list = null;
		try {
			list = log_timer_runlogDao.getList( map );
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		return list;
	}
	
	/**
	 * 查询数据总数方法实现
	**/
	@Override
	public int getListCount(Map map) { 
		int count = 0;
		try {
			count = log_timer_runlogDao.getListCount( map );
		} catch (Exception e) {
				count = 0;
		}
		return count;
	}
	
	/**
	 * 数据删除方法实现
	**/
	@Override
	public boolean delete(Map map){ 
		boolean flag = false;
		try {
			log_timer_runlogDao.delete( map );
			flag = true;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		return flag;
	}
	
}
